using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using FreeLancer.HRB.Core;
using System.Threading;
using System.Globalization;
using FreeLancer.HRB.Core.Web.HttpHandlers;

namespace FreeLancer.HRB.WebApp
{
  public class Global : System.Web.HttpApplication
  {

    protected void Application_Start(object sender, EventArgs e)
    {

    }

    protected void Application_End(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// Sets the culture based on the language selection in the settings.
    /// </summary>
    void Application_PreRequestHandlerExecute(object sender, EventArgs e)
    {
      //if (!string.IsNullOrEmpty(WebAppSettings.Instance.Culture))
      //{
      //  if (!WebAppSettings.Instance.Culture.Equals("Auto"))
      //  {
      //    CultureInfo culture = CultureInfo.CreateSpecificCulture(WebAppSettings.Instance.Culture);
      //    Thread.CurrentThread.CurrentUICulture = culture;
      //    Thread.CurrentThread.CurrentCulture = culture;
      //  }
      //}
      if (!string.IsNullOrEmpty(Language.GetCulture(Context)))
      {
        if (!Language.GetCulture(Context).Equals("Auto"))
        {
          CultureInfo culture = CultureInfo.CreateSpecificCulture(Language.GetCulture(Context));
          Thread.CurrentThread.CurrentUICulture = culture;
          Thread.CurrentThread.CurrentCulture = culture;
        }
      }
    }
  }
}